# -*- encoding:utf-8 -*-
'''
	pipelines_excel.py
	======================
	@descript: 
	@copyright:chinasoft
	@author:zhangsiqi
	@date: 2021-01-26 20:21
	@version:v1.0
'''
from openpyxl import Workbook


class Moviedy90Pipeline(object):
    def open_spider(self, spider):
        self.wb = Workbook()
        self.ws = self.wb.active
        # 设置表头
        self.ws.append(['电影名称','电影海报地址','电影类型','电影上映时间'])

    def process_item(self, item, spider):
        # 把数据中每一项整理出来
        for i in range(len(item['name'])):
            line = [item['name'][i],item['pic_url'][i],item['release_type'][i],item['release_time'][i]]
            self.ws.append(line)  # 将数据以行的形式添加到xlsx中
        return item

    def close_spider(self, spider):
        self.wb.save('content.xlsx')




if __name__ == '__main__':
    pass